package com.hunktimes.wholesale

import android.app.Application
import androidx.multidex.MultiDexApplication
import com.hunktimes.wholesale.mock.MockJsonParser
import com.hunktimes.wholesale.util.Constants
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import kotlin.concurrent.thread

/**
 * Author: Delete
 * Date: 2020/7/22 17:01
 * Description:
 *
 */
class App : MultiDexApplication() {

    companion object {
        private lateinit var instance: App
        fun get(): App = instance
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
        //Logger 初始化
        initLogger()

        //初始化mock dat
        initMockData()
    }

    /**
     * Logger 初始化
     */
    fun initLogger() {
        val formatStrategy = PrettyFormatStrategy
            .newBuilder()
            .showThreadInfo(false)
            .methodCount(0)
            .methodOffset(7)
            .tag(Constants.TAG)
            .build()
        val loggerAdapter = object : AndroidLogAdapter(formatStrategy) {
            override fun isLoggable(priority: Int, tag: String?): Boolean = BuildConfig.DEBUG
        }
        Logger.addLogAdapter(loggerAdapter)
    }

    fun initMockData() {
        thread {
            MockJsonParser.parserGoods(this)
            MockJsonParser.parseJewels(this)
        }
    }
}